wildstaronlinefandomcom-20200222-history
WildStar Lua
__NOWYSIWYG__ This is the main reference for the WildStar Lua runtime, as implemented in the WildStar UI. The WildStar Lua runtime is based on Lua 5.1, and generally uses the same standard Lua functions listed on the official Lua web site. Some functions differ slightly in WildStar's implementation and are documented here as well for consistency. Reference Nearly all of these functions are part of the default Lua 5.1 runtime environment, described here. Notable omissions are the operating system, and file I/O libraries. /eval Print(_VERSION) debug: Lua 5.1 Core : (valsMsg) returns (val) - returns val if true, else throws Lua error with sMsg : () - forces garbage collection : () : (sMessage,level) - throws an error with error message. use pcall() (see below) to catch errors : () returns (nAddOn,nLimit) - gets AddOn memory used and current GC threshold in kB. : (any) returns (table) - gets stack frame of given function or stack level number. : (aObject) returns (mtable) - gets metatable for table or userdata : () : () : (sCode) returns (function) - gets a Lua function for a Lua code string sCode : () : (boolean or proxy) - creates a userdata with a sharable metatable. : (table, index) returns (key,value) - gets next key-value pair of the table, allowing you to walk a table : (func, arg1, arg2, ...) returns (boolean, results or sMessage) - true if successful execution of 'func' and return values, otherwise false and error message. : () : () : () : () : () : (nIndex, list) returns (number or item) - gets count if 'index' is "#", or item at 'index' : (function or integer, table) - sets table representing the stack frame for given function or stack level : (aObject, mtable) returns (any) - sets the metatable of a table or userdata, returns aObject : (any) - gets type of variable as a string: "number", "string", "table", "function" or "userdata" : (tablenStartnEnd) returns (...) - converts indexed values of table to an argument list : (function, fCallback) returns (boolean,results) - true if successfully executes function, or executes fCallback and returns false. results are return values of function or fCallback Strings These string functions are shorthand references to the Lua string library, which is available via "string.". See StringLibraryTutorial for more info. : (anybase) returns (number) - converts to number, or nil if fails. bases not 10 accept only unsigned integers : (any) - converts to a string, or nil if fails. These are custom string functions available in WS but not normal Lua. : (sValuenPlaces) returns (number) - rounds any type value to number of places. (Carbine) Tables These table functions are shorthand references to the Lua table library (which is available via "table.", see TableLibraryTutorial for more info). Be aware that some table functions only work with tables with proper numerical indexes, where {1 = "x", 3 = "y"} would have only one indexed value at 1. Not being aware of this fact is one major causes for bugs in code written in Lua. : (table) - gets an iterator of type integer to traverse a table : (table) - gets an iterator to traverse a table table : (table sep [, i [, j]]) returns (string) - build a string from table elements : (table, function) - runs function for each name-value in table. (deprecated, use pairs) : (table, function) - runs function for each index in table, in order. (deprecated, use ipairs) : (table) returns (number) - gets cached size of table array values. (deprecated, use #table operator) : (tablepos, value) - insert value into table at pos. default is end of table : (table) returns (number) - last positive numerical index. requires scan of whole table : (tablepos) returns (any) - remove and return element at pos. default is last entry in table : (table, number) - attempts to set cached table size value. (deprecated, like getn) : (tablecomp) - sort the elements in the table in-place, optionally using a custom comparator. Arithmetic : (a, b) - returns the integer remainder of a divided by b Bitwise WildStar includes the Lua BitLib library, which is available via "bit32." table, which provides access to C-style bitwise manipulation operators. This library uses the 32-bit integer size, e.g. bit32.lshift(2147483648, 1) = 0, because 1000 0000 0000 0000 0000 0000 0000 0000 -> 0000 0000 0000 0000 0000 0000 0000 0000. : (a, b) - returns a shifted arithmetically right b places : (w1, ...) - returns the bitwise and of the w's : (a) - returns the one's complement of a : (w1, ...) - returns the bitwise or of the w's : (···) returns (boolean) - true if bitwise and of all operands is not zero : (w1, ...) - returns the bitwise exclusive or of the w's : (n, startwidth) - gets set of bits from n. start is 0-31. default width is 1 : (x, disp) - returns x rotated left disp places : (a, b) - returns a shifted left b places : (n, v, start width) - gets copy n with bits set from value v. start is 0-31. default width is 1 : (x, disp) - returns x rotated right disp places : (a, b) - returns a shifted logically right b places Coroutine Coroutine functions should be used sparingly because of the amount of memory they use. See also * Lua, which has plenty of links to other reference material. * API types, with a list of Lua types and 'psudo-types' used in WS.